package jwd.adapter

import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
import android.support.v4.app.FragmentStatePagerAdapter
import java.util.ArrayList

/**
 * Created by udi on 17-7-31.
 */
class ViewPagerAdapter(manager: FragmentManager) : FragmentStatePagerAdapter(manager) {

    private val mFragmentList = arrayListOf<Fragment>()
    private val mTitles = arrayListOf<String>()

    override fun getItem(position: Int): Fragment {
        return mFragmentList[position]
    }

    override fun getCount(): Int {
        return mFragmentList.size
    }


    fun addFragment(fragment: Fragment, name: String) {
        mFragmentList.add(fragment)
        mTitles.add(name)
    }

    fun addFragment(fragment: Fragment) {
        mFragmentList.add(fragment)
    }

    override fun getPageTitle(position: Int): CharSequence {
        if (mTitles.size > 0) {
            return mTitles[position]
        } else {
            return super.getPageTitle(position)
        }
    }
}
